import { checkStatementOrder } from '@/api/order'
import { ref } from 'vue'
import { OrderAPIRequestParam } from '@/typings/api/order'

// 加载
const loading = ref(false)

// 表单
const form = ref<OrderAPIRequestParam.CheckStatementOrder>({
  checkType: 1,
  id: '',
  price: 0,
  remark: '',
  surePrice: 0,
})

/**
 * 驳回方法
 * @param {string} id - 工单id
 */
const reject = async (id: string) => {
  loading.value = true
  form.value.checkType = 2
  const res = await checkStatementOrder(id, form.value)
  loading.value = false
  return res.data as { code: number; success: boolean; message: string; data: object }
}

/**
 * 提交方法
 * @param {string} id - 工单id
 */
const submit = async (id: string) => {
  loading.value = true
  form.value.checkType = 1
  const res = await checkStatementOrder(id, form.value)
  loading.value = false
  return res.data as { code: number; success: boolean; message: string; data: object }
}

export default {
  form,
  loading,
  reject,
  submit,
}
